package com.cskaoyan.converter;

import lombok.SneakyThrows;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author stone
 * @date 2022/04/02 14:42
 */
@Component
public class String2DateConverter implements Converter<String, Date> {
    //@SneakyThrows
    @Override
    public Date convert(String source) {
        Date parse = null;
        try {
            parse = new SimpleDateFormat("yyyy-MM-dd").parse(source);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return parse;
    }
}
